#ifndef _H_LEDDISPLAY_H_
#define _H_LEDDISPLAY_H_

#include "config.h"
#include "led.h"


#define key_scan_time 100
/*通过宏修改IO口*/

/*段选端口模式定义*/
#define SegPort  P0
#define SegPortH_Mode P0MDH
#define SegPortL_Mode P0MDL


/*位选端口模式定义*/
#define PositionPort P4
#define PositionPortH_Mode xP4MDH
#define PositionPortL_Mode xP4MDL

#define ButtonPortH_Mode  P3MDH
#define ButtonPortL_Mode  P3MDL
#define Button_Pin  P35

#define Digg1_1  P40
#define Digg2_1  P41
#define Digg3_1  P42
#define Digg4_1  P43

#define Digg1_2  P44
#define Digg2_2  P45
#define Digg3_2  P46
#define Digg4_2  P47

/*****************digtal number 1*****************/
#define dig1_1\
				Digg1_1=1;\
				Digg2_1=0;\
				Digg3_1=0;\
				Digg4_1=0;\	
				Digg1_2=0;\
				Digg2_2=0;\
				Digg3_2=0;\
				Digg4_2=0;\	

#define dig2_1\
				Digg1_1=0;\
				Digg2_1=1;\
				Digg3_1=0;\
				Digg4_1=0;\	
				Digg1_2=0;\
				Digg2_2=0;\
				Digg3_2=0;\
				Digg4_2=0;\	
				
#define dig3_1\
				Digg1_1=0;\
				Digg2_1=0;\
				Digg3_1=1;\
				Digg4_1=0;\		
				Digg1_2=0;\
				Digg2_2=0;\
				Digg3_2=0;\
				Digg4_2=0;\	
				
#define dig4_1\
				Digg1_1=0;\
				Digg2_1=0;\
				Digg3_1=0;\
				Digg4_1=1;\	
				Digg1_2=0;\
				Digg2_2=0;\
				Digg3_2=0;\
				Digg4_2=0;\	

/*****************digtal number 2*****************/
#define dig1_2\
				Digg1_1=0;\
				Digg2_1=0;\
				Digg3_1=0;\
				Digg4_1=0;\	
				Digg1_2=1;\
				Digg2_2=0;\
				Digg3_2=0;\
				Digg4_2=0;\	

#define dig2_2\
				Digg1_1=0;\
				Digg2_1=0;\
				Digg3_1=0;\
				Digg4_1=0;\	
				Digg1_2=0;\
				Digg2_2=1;\
				Digg3_2=0;\
				Digg4_2=0;\	
				
#define dig3_2\
				Digg1_1=0;\
				Digg2_1=0;\
				Digg3_1=0;\
				Digg4_1=0;\		
				Digg1_2=0;\
				Digg2_2=0;\
				Digg3_2=1;\
				Digg4_2=0;\	
				
#define dig4_2\
				Digg1_1=0;\
				Digg2_1=0;\
				Digg3_1=0;\
				Digg4_1=0;\	
				Digg1_2=0;\
				Digg2_2=0;\
				Digg3_2=0;\
				Digg4_2=1;\	
				
				
				
/*数码管显示缓存*/
extern uint8_t  xdata  g_displayBuffer[9];

typedef struct
{
	 uint16_t   SET_TIME;
	 uint16_t   DEC_TIME;
	 uint16_t   INC_TIME;	
	 uint8_t   SET_KEY_LOCK; /*按键锁*/
	 uint8_t   DEC_KEY_LOCK; /*按键锁*/
	 uint8_t   INC_KEY_LOCK; /*按键锁*/
	 uint8_t   V_OR_A;       /*单位显示  0:电压，1:电流*/
		uint16_t  SET_Value;    /*菜单索引*/
	
}MENU;

typedef struct
{
 uint16_t noLoad_voltage;      /*空载电压*/
 uint8_t  noLoad_voltage_err;  /*空载电压偏差*/
 uint16_t load_voltage;        /*带载电压*/
 uint8_t  load_voltage_err;    /*带载电压偏差*/
 uint16_t load_current;        /*带载电流*/
 uint8_t  load_current_err;    /*带载电流偏差*/
 uint8_t  load_time;           /*带载时间*/
 uint8_t  noLoadShort_time;    /*空载短路时间*/
 uint8_t  LoadShort_time;      /*带载短路时间*/
 uint8_t  battery_time;        /*电瓶反接时间*/ 	   
 uint8_t  limit_current;       /*限流值*/
 uint8_t  limit_current_err;   /*限流偏差*/
}MENU_PARE;


typedef struct 
{
	uint8_t red:1;
	uint8_t green:1;
	
}SEG_LED;

typedef union
{
  uint8_t  seg_position;
	 struct 
 	{
			uint8_t  pos1:1;
			uint8_t  pos2:1;
			uint8_t  pos3:1;
			uint8_t  pos4:1;
			uint8_t  pos5:1;
			uint8_t  pos6:1;
			uint8_t  pos7:1;
			uint8_t  pos8:1;			
	 }SEG_BIT;

}SEG_POS;


extern SEG_LED seg_led;

extern MENU_PARE menu_para;

extern MENU Menu;

extern 	SEG_POS seg_pos;  

void ledDisplay_init(void);

void LedDisplay_scan(uint8_t showPosition,uint8_t *buffer);

void  seg_led_write(COLOR color,PIN_LEVEL pin_level);

void Menu_change(void);
	
void set_displayBuffer(uint8_t showPosition,uint8_t point,uint8_t *buffer,uint8_t value);

uint16_t get_parameterChange(void);

void check_parameterChange(void);

void clear_displayBuffer(uint8_t *buffer);

#endif
